﻿using System;
using Ewk.Math.Algebra.UnitTests.MatrixTests.NumericTests;
using Ewk.Math.ComputationTypes;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Ewk.Math.Algebra.UnitTests.MatrixSearchTests
{
    public abstract class GetFirstRowNumberContainingZeroTestBase<T> : NumericTestBase<T>
        where T : struct, IComparable, IFormattable, IConvertible, IComparable<T>, IEquatable<T>
    {
        protected override Matrix<T> Matrix
        {
            get
            {
                return CreateMatrix(new[,]
                    {
                        {Computable<T>.Factory.One.Value, Computable<T>.Factory.Zero.Value, Computable<T>.Factory.One.Value, Computable<T>.Factory.Zero.Value, },
                        {Computable<T>.Factory.Zero.Value, Computable<T>.Factory.One.Value, Computable<T>.Factory.Zero.Value, Computable<T>.Factory.One.Value, },
                        {Computable<T>.Factory.One.Value, Computable<T>.Factory.Zero.Value, Computable<T>.Factory.One.Value, Computable<T>.Factory.Zero.Value, },
                        {Computable<T>.Factory.Zero.Value, Computable<T>.Factory.One.Value, Computable<T>.Factory.Zero.Value, Computable<T>.Factory.One.Value, },
                    });
            }
        }

        [TestMethod]
        public void When_a_matrix_contains_a_zero_in_the_second_row_of_the_first_column_Then_GetFirstRowNumberContainingZero_for_the_first_column_returns_1()
        {
            var i = Matrix.GetFirstRowNumberContainingZero(0);
            Assert.AreEqual(1, i);
        }

        [TestMethod]
        public void When_a_matrix_contains_a_zero_in_the_first_row_of_the_second_column_Then_GetFirstRowNumberContainingZero_for_the_second_column_returns_0()
        {
            var i = Matrix.GetFirstRowNumberContainingZero(1);
            Assert.AreEqual(0, i);
        }

        [TestMethod]
        public void When_a_matrix_contains_a_zero_in_the_second_row_of_the_first_column_Then_GetFirstRowNumberContainingZero_starting_from_the_second_row_for_the_first_column_returns_1()
        {
            var i = Matrix.GetFirstRowNumberContainingZero(1, 0);
            Assert.AreEqual(1, i);
        }

        [TestMethod]
        public void When_a_matrix_contains_a_zero_in_the_third_row_of_the_second_column_Then_GetFirstRowNumberContainingZero_starting_from_the_second_row__for_the_second_column_returns_2()
        {
            var i = Matrix.GetFirstRowNumberContainingZero(1, 1);
            Assert.AreEqual(2, i);
        }

        [TestMethod]
        public void When_a_matrix_contains_a_zero_in_the_fourth_row_of_the_first_column_Then_GetFirstRowNumberContainingZero_starting_from_the_third_row_for_the_first_column_returns_3()
        {
            var i = Matrix.GetFirstRowNumberContainingZero(2, 0);
            Assert.AreEqual(3, i);
        }

        [TestMethod]
        public void When_a_matrix_contains_a_zero_in_the_third_row_of_the_second_column_Then_GetFirstRowNumberContainingZero_starting_from_the_third_row__for_the_second_column_returns_2()
        {
            var i = Matrix.GetFirstRowNumberContainingZero(2, 1);
            Assert.AreEqual(2, i);
        }

        [TestMethod]
        public void When_a_matrix_contains_a_zero_in_the_fourth_row_of_the_first_column_Then_GetFirstRowNumberContainingZero_starting_from_the_fourth_row_for_the_first_column_returns_3()
        {
            var i = Matrix.GetFirstRowNumberContainingZero(3, 0);
            Assert.AreEqual(3, i);
        }

        [TestMethod]
        public void When_a_matrix_contains_a_zero_in_the_third_row_of_the_second_column_Then_GetFirstRowNumberContainingZero_starting_from_the_fourth_row__for_the_second_column_returns_NotFound()
        {
            var i = Matrix.GetFirstRowNumberContainingZero(3, 1);
            Assert.AreEqual(MatrixSearch.NotFound, i);
        }
    }
}